package com.pets.springboot_petshop.controller;

import com.pets.springboot_petshop.entity.Homecarousel;
import com.pets.springboot_petshop.pojo.Result;
import com.pets.springboot_petshop.service.HomecarouselService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/homecarousel")
public class HomecarouselController {
    @Autowired
    private HomecarouselService homecarouselService;


    @GetMapping("/selectHomecarousel")
    public Result selectHomecarousel(@RequestParam Integer id) {
        Homecarousel homecarousel = homecarouselService.selectHomecarousel(id);
        if (homecarousel != null) {
            return Result.success(homecarousel);
        }else {
            return Result.error("获取失败");
        }
    }
    @GetMapping("/findAll")
    public Result findAll() {
        List<Homecarousel> homecarousels = homecarouselService.findAll();
        if (homecarousels != null) {
            return Result.success(homecarousels);
        }else{
            return Result.error("获取失败");
        }
    }
    @GetMapping("selectname")
    private Result<List<Homecarousel>> selectname(@RequestParam String name) {
        List<Homecarousel> homecarousels = homecarouselService.selectname(name);
        if (homecarousels != null) {
            return Result.success(homecarousels);
        }else {
            return Result.error("获取失败");
        }
    }
    @PostMapping("/addHomecarousel")
    public Result addHomecarousel(@RequestBody Homecarousel Homecarousel) {
        if (homecarouselService.addHomecarousel(Homecarousel)>0){
            return Result.success("新增成功");
        }else {
            return Result.error("新增失败");
        }
    }
    @PostMapping("/deleteHomecarouselById")
    public Result deleteHomecarouselById(@RequestParam int id) {
        if (homecarouselService.deleteHomecarouselById(id) > 0) {
            return Result.success("删除成功");
        }else {
            return Result.error("删除失败");
        }
    }
    @PostMapping("updateHomecarouselById")
    public Result updateHomecarouselById(@RequestBody Homecarousel Homecarousel) {
        if (homecarouselService.updateHomecarouselById(Homecarousel) > 0) {
            return Result.success("修改成功");
        }else{
            return Result.error("修改失败");
        }
    }

}
